package net.hn.hnms.biz.meeting.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.meeting.request.MeetingRoomReq;
import net.hn.hnms.biz.meeting.service.MeetingRoomService;
import net.hn.hnms.biz.meeting.vo.MeetingRoomVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(value = "会议室管理", tags = {"会议室管理"})
@RestController
@RequestMapping("/meeting/room/management")
@RequiredArgsConstructor
public class MeetingRoomController extends BaseController {


    @Autowired
    private MeetingRoomService meetingRoomService;


    /**
     * 根据会议日期查询会议列表
     * @param meetingRoomReq
     * @param pageQuery
     * @return
     */
    @ApiOperation("会议室列表")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<MeetingRoomVo>> page(MeetingRoomReq meetingRoomReq, PageQuery pageQuery) {
        return R.ok(meetingRoomService.selectPageList(meetingRoomReq, pageQuery));
    }

    @ApiOperation("删除会议室")
    @SaCheckPermission("room:management:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除会议室", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        meetingRoomService.updateDeleteByIds(idList);
        return R.ok();
    }

    @ApiOperation("新增会议室")
    @SaCheckPermission("room:management:add")
    @PostMapping("/add")
    @Log(title = "新增会议室", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody MeetingRoomReq meetingRoomReq) {
        return toAjax(meetingRoomService.insert(meetingRoomReq));
    }


    @ApiOperation("更新会议室")
    @SaCheckPermission("room:management:update")
    @PostMapping("/update")
    @Log(title = "更新会议室", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody MeetingRoomReq meetingRoomReq) {
        meetingRoomService.updateById(meetingRoomReq);
        return R.ok();
    }

    @ApiOperation("会议室预约列表")
    @GetMapping("/reservation")
    @AutoSetMineCode
    public R<List<MeetingRoomVo>> reserve(@RequestParam(value = "dateTime",required = false)
                                              @DateTimeFormat(pattern = "yyyy-MM-dd")
                                                      Date dateTime,@ApiParam(value = "煤矿编码") String mineCode,@ApiParam(value = "公司编码") String companyCode) {
        return R.ok(meetingRoomService.selectReservePageList(dateTime,mineCode,companyCode ));
    }



    @ApiOperation("修改会议室状态")
    @SaCheckPermission("room:management:change")
    @PutMapping("/change")
    @Log(title = "修改会议室状态", businessType = BusinessType.UPDATE)
    public R<Void> change(@RequestParam("meetingRoomId") String meetingRoomId, @RequestParam("state") Integer state) {
        meetingRoomService.changeStatus(meetingRoomId, state);;
        return R.ok();
    }


}
